<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <meta http-equiv="Pragma" content="no-cache">
 <meta http-equiv="Cache-Control" content="no-cache">
 <meta http-equiv="Expires" content="Sat, 01 Dec 2001 00:00:00 GMT">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script language="javascript" type="text/javascript">
// <!CDATA[

function Button1_onclick() {
if(document.myForm.FirstName.value == "")
		alert("Your First Name must not be null!!!");
else if(document.myForm.LastName.value == "")
		alert("Your Last Name must not be null!!!");
else if(document.myForm.Address.value == "")
		alert("Your Address must not be null!!!");
else if(document.myForm.ZipCode.value == "")
		alert("Your Zip Code must not be null!!!");
else if(document.myForm.Email.value == "")
		alert("Your Email must not be null!!!")    ;
else{document.myForm.submit();}
}

function ButtonDel_onclick() {
	alert("Delete");
	document.myForm.target.value = "deleteuser";
	document.myForm.submit();
	}

function Button2_onclick() {
    window.open("EditUser.jsp","_self");

}


// ]]>
</script>


<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Island Auctions - Edit User</title>
</head>

<body>
<table width="100%" height="100%" border="2">
  <tr>
    <td width="22%" height="95"><img src="logo.png" width="163" height="154" alt="Logo" /></td>
    <td width="78%"><h1>Island Auctions</h1>
    <p> Turning Junk Into Money</p></td>
  </tr>
  <tr>
    <td valign="top"><p><a href="index.jsp">Home</a></p>
    <p><a href="Browse.jsp">Browse</a></p>
    <p><a href="SearchByType.jsp">Search</a></p>
    <p><a href="profile.jsp">Profile</a></p>
    <p><a href="Users.jsp">Users</a></p>
    <p><a href="login.jsp">Login/Logout</a></p>
    <p><a href="index.jsp">(Manage Employees)</a></p></td>
    <td valign="top">Content Goes Here!!!!!!!!!
    
    <%String UserName = request.getParameter("UserName");

String mysJDBCDriver = "com.mysql.jdbc.Driver"; 
String mysURL = "jdbc:mysql://mysql2.cs.stonybrook.edu:3306/jedale"; 
String mysUserID = "jedale"; 
String mysPassword = "107200855";
Class.forName(mysJDBCDriver).newInstance();
java.util.Properties sysprops=System.getProperties();
sysprops.put("user",mysUserID);
sysprops.put("password",mysPassword);

//connect to the database
java.sql.Connection conn=null;
		conn=java.sql.DriverManager.getConnection(mysURL,sysprops);
		System.out.println("Connected successfully to database using JConnect");

		java.sql.Statement stmt1=conn.createStatement();
try{            	


	java.sql.ResultSet rs = stmt1.executeQuery("SELECT Person.LastName, Person.FirstName, Person.Address, Person.ZipCode,Person.Telephone, Person.Email, Employee.HourlyRate, Employee.EmployeeID,	Person.Pass, Employee.EmpLevel FROM Person, Employee WHERE  Employee.EmployeeID = Person.SSN AND Person.Username = '" +UserName+"'");
	if(!rs.next())
	{
		System.out.println("Fail 865");
		response.sendRedirect("index.jsp");
	
	}
	String FirstName = rs.getString(2);
	String LastName =rs.getString(1);
	String Address = rs.getString(3);
	String HR = rs.getString(7);
	String Email = rs.getString(6);
	String Telephone = rs.getString(5);
	String ZipCode = rs.getString(4);
	String IDNumber = rs.getString(8);
	String CurrentPass = rs.getString(9);
	String Level = rs.getString(10);
	
	%>
    
        <table border="0" cellpadding="0" cellspacing="0" style="font-size: 14pt; width: 100%;
        height: 100%" id="TABLE1"">
        <tr>
            <td colspan="2" style="height: 63px; text-align: center; background-color: gray;">
                Edit User</td>
        </tr>
        <tr>

        	<form name="myForm" action="usercreate.jsp" method="post">
        		<input type="hidden" name="target" value="editemployee">
        		<input type="hidden" name="SSN" value="<%=IDNumber%>">
        		<input type="hidden" name="Password1" value="<%=CurrentPass%>">
        		<input type="hidden" name="Id" value="<%=UserName%>">
            <td style="width: 220px; height: 426px; vertical-align: top; text-align: left;">
                <span style="font-size: 10pt"><strong>First Name:<br />
                    <input value="<%=FirstName %>" name="FirstName" style="font-weight: bold; font-size: 10pt; width: 145px"
                        type="text" /><br />
                                        <span style="font-size: 10pt"><strong>Last Name:<br />
                    <input value="<%=LastName%>" name="LastName" style="font-weight: bold; font-size: 10pt; width: 145px"
                        type="text" /><br />
                                       
                    EMail Address:<br />
                    <input value="<%=Email%>" id="Email" name="Email" style="width: 145px" type="text" /><br />
                    <br />
                    Your Address: &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
                    <br />
                    <input value="<%=Address%>" id="Address" name="Address" style="width: 250px; height: 12px"></input><br />
                          Zip Code:<br />
                    <input value="<%=ZipCode%>" id="ZipCode" name="ZipCode" style="width: 145px" type="text" /><br />
                    <br />
                      <span style="font-size: 10pt"><strong>Telephone:<br />
                    <input value="<%=Telephone%>" name="Telephone" style="font-weight: bold; font-size: 10pt; width: 145px"
                        type="text" /><br />
                                        <span style="font-size: 10pt"><strong>Hourly Rate:<br />
                    <input value="<%=HR%>" name="Hourly" style="font-weight: bold; font-size: 10pt; width: 145px"
                        type="text" /><br />
                                                              <span style="font-size: 10pt"><strong>Employee Level:<br />
                    <input value="<%=Level%>" name="Level" style="font-weight: bold; font-size: 10pt; width: 145px"
                        type="text" /><br />
                    <input id="Button1" type="button" value="Finish"  onclick="return Button1_onclick()" />
                    &nbsp;
                    <input id="Button3" type="button" value="Cancel"  onclick="window.open('','_self');" /><br />
                    <br>
                    <br>
                    <input id="ButtonDel" type="button" value="Delete"  onclick="return ButtonDel_onclick()" />
                    &nbsp;
                </strong></span>
           </form>
        </tr>
        <tr>
            <td style="width: 220px; background-color: yellow;">
            </td>
            <td style="vertical-align: top; background-color: yellow; text-align: justify; width: 355px;">
            </td>
        </tr>
    </table>
    <%
	} catch(Exception e)
	{
		e.printStackTrace();
		out.print(e.toString());
	}
	finally{
	
		try{conn.close();}catch(Exception ee){};
	}
%>
    </td>
  </tr>
</table>
</body>
</html>